package URL_download;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

public class TestURL {
	public static void main(String[] args) throws Exception{
		URL url=new URL("");
		System.out.println(url.getFile());
		System.out.println(url.getHost());
		System.out.println(url.getProtocol());
		System.out.println(url.getPort());
		
		System.out.println("download file");
		download (url, "f:\\save.html");
	}
	static void download (URL url, String luufile) throws Exception{
		InputStream ip=url.openStream();
		FileOutputStream fo=new FileOutputStream(luufile);
		byte []buff=new byte[1024];
		int len=0;
		
		while ((len=ip.read(buff))!=-1){
			fo.write(buff, 0, len);
			fo.flush();
		}
		ip.close();fo.close();
	}
}
